package com.sheyu.mall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author sheyu
 * @Desciption:
 * @date 2020/9/9 9:40 下午
 */
public class OrderConfirmVo {

    @Getter @Setter
    /**
     * 会员收货地址
     */
    List<MemberAddressVo> memberAddressVos;

    @Getter @Setter
    /** 所有选中的购物项 **/
    List<OrderItemVo> items;

    //发票信息
    @Getter @Setter
    /**
     * 优惠券（会员积分）
     */
    private Integer integration;

    /**
     * 防止重复提交的令牌
     */
    @Getter @Setter
    private String orderToken;

    /**
     * 库存，skuId对应是否存在库存
     */
    @Getter @Setter
    Map<Long,Boolean> stocks;

    @Setter @Getter
    private Integer count;

    @Setter @Getter
    private BigDecimal total;

    @Setter @Getter
    private BigDecimal payPrice;

    public Integer getCount(){
        Integer count = 0;
        if (this.items!=null&&this.items.size()>0){
            for (OrderItemVo item:this.items){
                count += item.getCount();
            }
        }
        return count;
    }

    public BigDecimal getTotal(){
        BigDecimal totalNum = BigDecimal.ZERO;
        if (this.items!=null&&this.items.size()>0){
            for (int i = 0; i < this.items.size(); i++) {
                BigDecimal price = this.items.get(i).getPrice().multiply(new BigDecimal(this.items.get(i).getCount().toString()));
                totalNum = totalNum.add(price);
            }
        }
        return totalNum;
    }

    public BigDecimal getPayPrice(){
        return getTotal();
    }

}
